<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/content/variable.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<%@ include file="/content/head.jsp"%>
</head>
<body>
    <div class="row">
        <div class="col-md-12">
            <div class="box box-info">
                <div class="box-header with-border">
                    <h3 class="box-title">修改小说内容</h3>
                </div>
                <form id="editInfo" class="form-horizontal" role="form" onsubmit="javascript:saveInfo();">
                    <div class="box-body">
                        <div class="form-group">
                            <label for="fictionCover" class="col-sm-2 control-label">小说封面：</label>
                             <div class="col-md-8">
								<input type="file" class="file-loading" id="fictionCoverFile" accept="img/*">
								<input type="text" class="form-control input-sm" id="fictionCoverUrl" name="fictionCover" value="${obj.fictionCover}"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="fictionName" class="col-sm-2 control-label">小说名称：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="fictionName" class="form-control" name="fictionName" value="${obj.fictionName}"
                                       placeholder="小说名称">
                            </div>
                        </div>
                        <br>
                         <div class="form-group">
                            <label for="fictionHtmlUrl" class="col-sm-2 control-label">小说内容地址：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="fictionHtmlUrl" class="form-control" name="fictionHtmlUrl" value="${obj.fictionHtmlUrl}"
                                       placeholder="小说内容地址">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="fictionTxtUrl" class="col-sm-2 control-label">上传txt文件生成的地址：</label>
                            <div class="col-md-8">
								<input type="file" class="file-loading" id="fictionTxtUrlFile" accept="*/*">
								<input type="text" class="form-control input-sm" id="fictionTxtUrl" name="fictionTxtUrl" value="${obj.fictionTxtUrl}"> 
							</div>
							<div class="col-sm-2">
								<span class="help-inline" style="color: #a94442"></span>
							</div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="fictionType" class="col-sm-2 control-label">小说类型：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="fictionType" class="form-control" name="fictionType" value="${obj.fictionType}"
                                       placeholder="小说类型">
                            </div>
                        </div>
                        <br>
                         <div class="form-group">
                            <label for="fictionAuthor" class="col-sm-2 control-label">小说作者：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="fictionAuthor" class="form-control" name="fictionAuthor" value="${obj.fictionAuthor}"
                                       placeholder="小说作者">
                            </div>
                        </div>
                        <br>
                        <div class="form-group">
                            <label for="fictionNum" class="col-sm-2 control-label">小说简介：</label>
                            <div class="col-sm-8 ">
                                <input type="text" id="fictionNum" class="form-control" name="fictionNum" value="${obj.fictionNum}"
                                       placeholder="小说简介">
                            </div>
                        </div>
                        <br>
                         <input type="hidden" name ="id" id="id" value="${obj.id}"/>
                        <div class="col-md-offset-5 col-md-9">
                            <button type="submit" class="btn btn-success">确定</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <!-- /.row -->
<%@ include file="/content/js.jsp"%>
<script type="text/javascript">
$(function(){
//封面上传
   $("#fictionCoverFile").fileinput({
   	uploadUrl:"<%=path%>/fiction/uploadOSS",
       browseClass: "btn btn-primary",
       enctype: 'multipart/form-data',
       autoReplace:true,
       dropZoneEnabled:false,
       browseLabel: "上传",
       showCaption: false,
       showRemove: false,
       showUpload: true,
       showZoom:false,
       maxFileCount:1, ////表示允许同时上传的最大文件个数
       allowedFileTypes:["image"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
       previewSettings:{
       	image: {width: "auto", height: "100px"},
       },
   });
   $('#fictionCoverFile').on('fileuploaded', function(event, data, previewId, index) {
   	var path = data.response.initialPreviewConfig[0].extra.path;
       $("#fictionCoverUrl").val(path);
   });
   $('#fictionCoverFile').on('filedeleted', function(event,key,jqXHR,data) {
   	if($("#fictionCoverUrl").val()==data.path)
   		$("#fictionCoverUrl").val('');
   }); 

   $("#fictionTxtUrlFile").fileinput({
   	uploadUrl:"<%=path%>/fiction/uploadOSS",
       browseClass: "btn btn-primary",
       autoReplace:true,
       dropZoneEnabled:false,
       browseLabel: "上传",
       showCaption: false,
       showRemove: false,
       showPreview:false,
       showUpload: true,
       showZoom:false,
       maxFileCount:1, ////表示允许同时上传的最大文件个数
//        allowedFileTypes:["video"], //文件的选择类型[‘image’, ‘html’, ‘text’, ‘video’, ‘audio’, ‘flash’, ‘object’]
       maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
       previewSettings:{
       		type:"video",
    		video: {width: "auto", height: "100px"},
      },
   });
   $('#fictionTxtUrlFile').on('fileuploaded', function(event, data, previewId, index) {
   	var path = data.response.initialPreviewConfig[0].extra.path;
       $("#fictionTxtUrl").val(path);
       $("#fictionTxtUrl").triggerHandler("blur");
   });
   $('#fictionTxtUrlFile').on('filedeleted', function(event,key,jqXHR,data) {
   	if($("#fictionTxtUrl").val()==data.path)
   		$("#fictionTxtUrl").val('');
   	$("#fictionTxtUrl").triggerHandler("blur");
   }); 
});

	function saveInfo(){
		var id = $("#id").val();
		var fictionCover = $("#fictionCoverUrl").val();
		var fictionName = $("#fictionName").val();
		var fictionHtmlUrl = $("#fictionHtmlUrl").val();
		var fictionTxtUrl = $("#fictionTxtUrl").val();
		var fictionType = $("#fictionType").val();
		var fictionAuthor = $("#fictionAuthor").val();
		var fictionNum = $("#fictionNum").val();
		$.ajax({
			type:"post",
			async: false,
			url:"<%=path%>/fiction/alertFictionSave",
			data:{id:id,
				fictionCover:fictionCover,
				fictionName:fictionName,
				fictionHtmlUrl:fictionHtmlUrl,
				fictionTxtUrl:fictionTxtUrl,
				fictionType:fictionType,
				fictionAuthor:fictionAuthor,
				fictionNum:fictionNum},
			dataType:"json",
			success: function(data){
				if (data.missage == "success") {
                    modalMsg("修改成功", "success");
                    window.parent.location.reload();
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }else if(data.missage == "error"){
                	 modalMsg("修改失败", "error");
                }else{
                	 modalMsg("更新失败", "error");
                }
			}
		});
	}
</script>
</body>
</html>